package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.PraiseRes;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.PraiseResService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 praiseResController
@RequestMapping("/praiseResController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /praiseResController
public class PraiseResController {
	@Resource
    PraiseResService praiseResService;
	@RequestMapping("/getAllPraiseRes")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<PraiseRes> getAllPraiseRes() throws Exception{
    	System.out.println("查询饭店点赞记录");
    	return praiseResService.getAllPraiseRes();
    }
	@RequestMapping("/addPraiseRes")
	@ResponseBody
	public DTO<PraiseRes> addPraiseRes(@RequestBody PraiseRes praiseRes) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加饭店点赞记录成功");
		return praiseResService.addPraiseRes(praiseRes);
	}

	@RequestMapping("/deletePraiseResByUrid/{urid}")
	@ResponseBody
    public DTO<PraiseRes> deletePraiseResByUrid(@RequestBody @PathVariable("urid") String urid) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(urid+"删除饭店点赞记录成功");
    	return praiseResService.deletePraiseResByUrid(urid);
    }



	@RequestMapping("/getPraiseResByUrid/{urid}")
	@ResponseBody
	public DTO<PraiseRes> getPraiseResByUrid(@PathVariable("urid") String urid) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(urid+"根查询饭店点赞记录成功");
		return praiseResService.getPraiseResByUrid(urid);
	}

	@RequestMapping("/updatePraiseResByUrid")
	@ResponseBody
	public DTO<PraiseRes> updatePraiseResByUrid(@RequestBody PraiseRes praiseRes) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改饭店点赞记录成功");
		System.out.println(praiseRes);
		return praiseResService.updatePraiseResByUrid(praiseRes);
	}

	@RequestMapping("/getPraiseResByPage")
	@ResponseBody
	public DTO<PraiseRes> getPraiseResByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询饭店点赞记录成功");
		return praiseResService.getPraiseResByPage(pageInfo);
	}

}
